<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<%@ page import="oneroom.user.subway.subwayModel" %>
<jsp:useBean id="codeDao" scope="page" class="oneroom.admin.code.codeDao" />
<jsp:useBean id="subdao" scope="page" 	class="oneroom.user.subway.subwayDao" />
<%
	List codeList = codeDao.getDtlList("001");
	String pageName = "sub_list.jsp";
	String viewName = "sub_view.jsp";
	int     giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int     giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	
	String subway 	= request.getParameter("subway") 	== null ? "" : request.getParameter("subway");
	String maincode = request.getParameter("maincode") 	== null ? "" : request.getParameter("maincode");
	String sort 	= request.getParameter("sort") 		== null ? "date" : request.getParameter("sort");	
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 15;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	List roomList  = subdao.getSubway( subway, 
									 sort,			
									 giSelectPage, 
									 giPageSize);
	if (roomList.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = subdao.getCount(subway); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>원룸몬스터</title>
<link href="/room/css/all.css" rel="stylesheet" type="text/css" />
<script src="/room/script/swfobject_modified.js" type="text/javascript"></script>
<script src="/room/script/common.js" type="text/javascript"></script>
<script src="/room/script/jquery-1.3.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	<%if(!maincode.equals("")){ //주소 검색을 하였을 경우 주소 선택한 항목에 보여주기 위한 작업 읍면동을 가지고옴%>
		$.ajax({type : "post",
			url : "/room/subway/sub1.jsp",
			dataType : "html",
			data : "maincode=<%=maincode%>",
			success : function(msg){
				document.getElementById("hosen").innerHTML = msg;
			}
		});
	<%}%>

	$('#datesort').click(function() {
		document.getElementById("sort").value="date";
		document.getElementById("frm").action = "sub_list_main.jsp";		
		document.getElementById("frm").submit();
	});
	$('#depositsort').click(function() {
		document.getElementById("sort").value="deposit";
		document.getElementById("frm").action = "sub_list_main.jsp";			
		document.getElementById("frm").submit();
	});
	$('#monthsort').click(function() {
		document.getElementById("sort").value="month";
		document.getElementById("frm").action = "sub_list_main.jsp";			
		document.getElementById("frm").submit();
	});	

});
function subway(maincode){
	$.ajax({type : "post",
		url : "/room/subway/sub1.jsp",
		dataType : "html",
		data : "maincode="+maincode,
		success : function(msg){
			document.getElementById("hosen").innerHTML = msg;
		}
	});
}

function seachSubway(subway,maincode){
	document.getElementById("subway").value = subway;
	document.getElementById("maincode").value = maincode;
	document.getElementById("frm").submit();
}
function goView(oneroomseq){
	document.frmView.oneroom_seq.value = oneroomseq;
	document.frmView.submit();
}
//-->
</script>
</head>
<body>
<div align="center"> 

 <div id="content">

<!----------------왼쪽---------------->  
<%@ include file="/room/common/left.jsp" %> 

<!----------------왼쪽끝---------------->  


<!----------------가운데 시작----------------> 
 <div id="rgt">
  <div id="con01">
   <div class="top bb1"><img src="/room/img/txt_top.gif" /></div>
   
   <div id="sch-adress">
     <form action="sub_list.jsp" method="post" name="frm" id="frm">
     <div><img src="/room/img/title_cube.gif"/></div>
     <div class="bg_adress">
       <div class="pt15 pb10 bb1" style="width:575px;">
       <span class="fw c_org">
		<input type="hidden" name="subway" value="<%=subway %>" id="subway" />
		<input type="hidden" name="maincode" value="" id="maincode" />
		<input type="hidden" name="sort" value="<%=sort %>" id="sort" />
		
		<%
		for(int i = 0; i<codeList.size(); i++){
			codeModel mode = (codeModel)codeList.get(i);
		%>
		<a class="c" href="javascript:subway('<%=mode.getCode() %>')"><%=mode.getCodename() %></a> |
		<%if(((i+1)%11) == 0 && i > 0) {%>
		<br />
		<%} %>
		<%} %>
		</span> 
		</div>  
		<div id="hosen">
		</div>
 
 

       <!-- <div><img src="/room/img/cube_c02.jpg" /></div>
       <div><img src="/room/img/img_cube_city.gif" border="0" usemap="#Map2"/>
         <map name="Map2" id="seoul">
           <area shape="rect" coords="19,15,65,33" href="#" />
           <area shape="rect" coords="20,40,66,58" href="#" />
           <area shape="rect" coords="82,14,130,34" href="#" />
           <area shape="rect" coords="83,40,130,56" href="#" />
           <area shape="rect" coords="144,14,191,34" href="#" />
           <area shape="rect" coords="142,40,192,59" href="#" />
           <area shape="rect" coords="208,14,255,32" href="#" />
           <area shape="rect" coords="206,40,256,61" href="#" />
           <area shape="rect" coords="271,16,319,33" href="#" />
           <area shape="rect" coords="271,39,324,58" href="#" />
           <area shape="rect" coords="335,15,406,32" href="#" />
           <area shape="rect" coords="336,39,408,58" href="#" />
           <area shape="rect" coords="423,15,478,33" href="#" />
           <area shape="rect" coords="495,14,549,33" href="#" />
         </map>
       </div> -->
       
     
     </div>
     <div><img src="/room/img/bg_box_bottom.jpg" /></div>
    </form>  
   </div>
 
<!------------------리스트 시작---------------------->
 <div class="pt15 pl10" style="width:600px">
   <div>
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <col width="77px" /> <col width="77px" /><col width="447px" />
    <tr>
     <td><a href="#"><img src="/room/img/tab_01<%if(sort.equals("date")){out.print("_on");} %>.gif" id="datesort" onmouseover="MM_swapImage('datesort','','/room/img/tab_01_on.gif',1)" onmouseout="MM_swapImgRestore()"/></a></td>
     <td><a href="#"><img src="/room/img/tab_02<%if(sort.equals("deposit")){out.print("_on");} %>.gif" id="depositsort" onmouseover="MM_swapImage('depositsort','','/room/img/tab_02_on.gif',1)" onmouseout="MM_swapImgRestore()"/></a></td>
     <td class="bb2">&nbsp;</td>
   </tr>
  </table>
  </div>
 <!--탭끝-->

<%
	if(roomList != null && roomList.size() > 0){
		giCount  = 1;
		giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
		giStartPos = ((giCurPage - 1) * giPageSize) + 1;
	
		for(int i=0; i<roomList.size(); i++){
			subwayModel model = (subwayModel)roomList.get(i);
%>
 <div class="pt10 pb10 bb1">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <col width="109px;" />
   <col width="329px;" />
   <col width="100px;" />
   <col width="62px;" />
   
  <tr>
    <td class="thum01"><a href="javascript:goView('<%=model.getOneroom_seq() %>');"><%if(model.getPhoto1_main().equals("1")){ %>
			<img src="/download/<%=model.getPhoto1_small() %>?name=<%=model.getPhoto1_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("2")){ %>
			<img src="/download/<%=model.getPhoto2_small() %>?name=<%=model.getPhoto2_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("3")){ %>
			<img src="/download/<%=model.getPhoto3_small() %>?name=<%=model.getPhoto3_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("4")){ %>
			<img src="/download/<%=model.getPhoto4_small() %>?name=<%=model.getPhoto4_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("5")){ %>
			<img src="/download/<%=model.getPhoto5_small() %>?name=<%=model.getPhoto5_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("6")){ %>
			<img src="/download/<%=model.getPhoto6_small() %>?name=<%=model.getPhoto6_small() %>&kind=img" />
		<%} %></a></td>
    <td valign="top" class="pt5 pl10">매물종류 : <%=model.getRoomkind() %> &nbsp;&nbsp;<span class="fw"><%=model.getTitle() %></span><br /><br />
    임대종류 : <%if (model.getRoommoney() != ""){ %>전세&nbsp;&nbsp;<span class="c_org fs11"> <%=model.getRoommoney() %></span>
    <%}else if(model.getRoommonth1() != ""){ %>월세&nbsp;&nbsp;<span class="c_org fs11"> <%=model.getRoommonth1() %>/<%=model.getRoommonth2() %></span>
    <%} %>
    <br/>    
    <br/>    
    <br/>
    위치 : <%=model.getAddress1() %>&nbsp;&nbsp;<%=model.getAddress2() %>&nbsp;&nbsp;<%=model.getAddress3() %>    
    <td valign="top" class="pt5"><%=model.getCreatedate() %>    
    </td>
    <td valign="top" class="pt5 fw"><%=model.getCreateid() %>
    <br/><%if(Integer.parseInt(model.getReport_cnt()) >= 2){%>거래완료<%} %>    
    </td>
  </tr>
</table>
</div>

<%
		giCount = giCount + 1;
		giRecordcnt = giRecordcnt - 1;
	
		}
	}else{ 
%>
<div class="pt10 pb10 bb1">
	  <table width="100%" border="0" cellspacing="0" cellpadding="0">
	   <col width="100%" />
	  <tr>
	  	<td>
	  		검색된 매물 정보가 없습니다.
	  	</td>
	  </tr>
	</table>
</div>
<%} %>
	<%@ include file="/room/common/sub_page.jsp" %>
</div>

</div>  
<!----------------가운데 끝---------------->


<!----------------오른쪽 시작---------------->    
  <%@ include file="/room/common/right.jsp" %>  
<!----------------오른쪽 끝---------------->
</div>


<!-------------푸터영역----------> 
<%@ include file="/room/common/footer.jsp" %> 

<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>

<form action="sub_view.jsp" method="post" name="frmView" >
<input type="hidden" name="txtSelectPage" value="<%=giSelectPage %>"/>
<input type="hidden" name="txtSelectBlock" value="<%=giSelectBlock %>"/>
<input type="hidden" name="sort" value="<%=sort %>"/>
<input type="hidden" name="oneroom_seq" value=""/>
</form>	
</body>
</html>

